From 7c6274d46fd4285ebcd0f1c1dd3d229df30fbb44 Mon Sep 17 00:00:00 2001 From: Factiven Date: Mon, 22 May 2023 13:11:45 +0700 Subject: Update v3.6.0 > We switch back to gogo as a source and this will fix the video won't play on iOS devices > Removed subtitle function since gogo doesn't provide external subtitle --- pages/anime/[...id].js | 174 +++++-------------------------------------------- 1 file changed, 16 insertions(+), 158 deletions(-) (limited to 'pages/anime/[...id].js') diff --git a/pages/anime/[...id].js b/pages/anime/[...id].js index cd37525..867e429 100644 --- a/pages/anime/[...id].js +++ b/pages/anime/[...id].js @@ -20,7 +20,6 @@ import Modal from "../../components/modal"; import { signIn, useSession } from "next-auth/react"; import AniList from "../../components/media/aniList"; import ListEditor from "../../components/listEditor"; -import { closestMatch } from "closest-match"; const query = ` query ($username: String, $status: MediaListStatus) { @@ -143,12 +142,10 @@ const infoQuery = `query ($id: Int) { export default function Info({ info, color }) { const { data: session } = useSession(); - const [data, setData] = useState(null); const [episode, setEpisode] = useState(null); const [loading, setLoading] = useState(false); const [progress, setProgress] = useState(0); const [statuses, setStatuses] = useState(null); - const [stall, setStall] = useState(false); const [domainUrl, setDomainUrl] = useState(""); const [showAll, setShowAll] = useState(false); @@ -157,9 +154,6 @@ export default function Info({ info, color }) { const [time, setTime] = useState(0); const { id } = useRouter().query; - const [epiStatus, setEpiStatus] = useState("ok"); - const [error, setError] = useState(null); - const rec = info?.recommendations?.nodes.map( (data) => data.mediaRecommendation ); @@ -167,121 +161,26 @@ export default function Info({ info, color }) { useEffect(() => { const { protocol, host } = window.location; const url = `${protocol}//${host}`; - setDomainUrl(url); - const defaultState = { - data: null, - // info: null, - episode: null, - loading: true, - statuses: null, - progress: null, - stall: false, - EpiStatus: "ok", - error: null, - }; - - // Reset all state variables to their default values - Object.keys(defaultState).forEach((key) => { - document.body.style.overflow = "auto"; - const value = defaultState[key]; - if (Array.isArray(value)) { - value.length - ? eval( - `set${ - key.charAt(0).toUpperCase() + key.slice(1) - }(${JSON.stringify(value)})` - ) - : eval(`set${key.charAt(0).toUpperCase() + key.slice(1)}([])`); - } else { - eval( - `set${key.charAt(0).toUpperCase() + key.slice(1)}(${JSON.stringify( - value - )})` - ); - } - }); async function fetchData() { + setLoading(true); if (id) { - setLoading(false); try { - const [res] = await Promise.all([ - fetch( - `https://api.moopa.my.id/meta/anilist/info/${id?.[0]}?provider=zoro` - ), - // fetch("https://graphql.anilist.co/", { - // method: "POST", - // headers: { - // "Content-Type": "application/json", - // }, - // body: JSON.stringify({ - // query: infoQuery, - // variables: { - // id: id?.[0], - // }, - // }), - // }), - ]); + setEpisode(null) + const res = await fetch(`https://api.moopa.my.id/meta/anilist/info/${info.id}`) const data = await res.json(); - // const infos = await info.json(); if (res.status === 500) { - setEpisode(null); - setEpiStatus("error"); - setError(data.message); + setEpisode([]); } else if (res.status === 404) { window.location.href("/404"); - } - // setInfo(infos.data.Media); - // setLog(data); - - // const textColor = setTxtColor(infos.data.Media.coverImage?.color); - - if (!data || data?.episodes?.length === 0) { - // const res = await fetch( - // `https://api.moopa.my.id/anime/gogoanime/${info.title.romaji}` - // ); - // const datas = await res.json(); - - // if (datas) { - // const release = datas.results.map((i) => i.releaseDate); - // const match = closestMatch(info.startDate.year, release); - // const filter = datas.results.find((i) => i.releaseDate === match); - - // // const found = filter.find((i) => i.title === info.title.romaji); - - // // setLog(found); - - // if (filter) { - // const res = await fetch( - // `https://api.moopa.my.id/anime/gogoanime/info/${filter.id}` - // ); - // const dataA = await res.json(); - // setEpisode(dataA.episodes); - // // setLog(dataA); - // } - // } - // if (res.status === 500) { - // setEpisode(null); - // setEpiStatus("error"); - // setError(datas.message); - // } else { + } else if (!data || data?.episodes?.length === 0) { setEpisode([]); - // } - // setColor({ - // backgroundColor: `${data?.color || "#ffff"}`, - // color: textColor, - // }); } else { - setEpisode(data.episodes); + setEpisode(data.episodes?.reverse()); } - // setColor({ - // backgroundColor: `${data?.color || "#ffff"}`, - // color: textColor, - // }); - if (session?.user?.name) { const response = await fetch("https://graphql.anilist.co/", { method: "POST", @@ -330,8 +229,7 @@ export default function Info({ info, color }) { ); } - setData(data); - setLoading(true); + setLoading(false); } catch (error) { console.log(error); setTimeout(() => { @@ -397,7 +295,7 @@ export default function Info({ info, color }) { )} - {session && loading && info && ( + {session && info && (

- {/* Yuru Campā–³ SEASON 2 */} {info?.title?.romaji || info?.title?.english}

{item} - {/* {index !== info?.genres?.length - 1 && ( - - )} */} ))}

@@ -471,7 +364,7 @@ export default function Info({ info, color }) { className="bg-action px-10 rounded-sm font-karla font-bold" onClick={() => handleOpen()} > - {loading + {!loading ? statuses ? statuses.name : "Add to List" @@ -533,7 +426,7 @@ export default function Info({ info, color }) { className="bg-action flex-center z-20 h-[20px] w-[180px] absolute bottom-0 rounded-sm font-karla font-bold" onClick={() => handleOpen()} > - {loading + {!loading ? statuses ? statuses.name : "Add to List" @@ -621,7 +514,7 @@ export default function Info({ info, color }) {
- {info && ( + {info?.relations?.edges?.length > 0 && (
Relations
@@ -721,7 +614,6 @@ export default function Info({ info, color }) {

Next :

{time}
@@ -732,10 +624,10 @@ export default function Info({ info, color }) {
)}
- {loading ? ( - data && ( + {!loading ? ( + episode && (
- {epiStatus === "ok" ? ( + { episode?.length !== 0 && episode ? ( episode?.map((epi, index) => { return ( @@ -744,9 +636,7 @@ export default function Info({ info, color }) { className="flex flex-col gap-3 px-2" > No Episodes Available

) - ) : ( - //

- // Something went wrong, can't retrieve any episodes :/ - //

-
- {/*

{epiStatus} while retrieving data

*/} -
-                            
-                              Something went wrong while retrieving data :/
-                            
-                          
-
- )} + }
) ) : ( @@ -815,8 +689,6 @@ export default function Info({ info, color }) { /> )} -
-
@@ -901,17 +773,3 @@ function setTxtColor(hexColor) { const brightness = getBrightness(hexColor); return brightness < 150 ? "#fff" : "#000"; } - -const getLanguageClassName = (language) => { - switch (language) { - case "javascript": - return "language-javascript"; - case "html": - return "language-html"; - case "bash": - return "language-bash"; - // add more languages here as needed - default: - return ""; - } -}; -- cgit v1.2.3